var express = require('express');
var app = express();
var bodyParser = require('body-parser');//用于req.body获取值的
// 处理静态资源
app.use(express.static('public'))
// 处理参数
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
//  ------------------
//  这个文件时在学习vue的前端交互时用于测试的
// -------------------

// app.get('*', function (req, res, next) {
//   res.header("Access-Control-Allow-Origin", "*");
//   res.header("Access-Control-Allow-Methods", "PUT,GET,POST,DELETE,OPTIONS");
//   res.header("Access-Control-Allow-Headers", "X-Requested-With");
//   res.header("Access-Control-Allow-hEADERS", "Content-Type");
//   next();
// });

app.get('/', function (req, res) {
  res.send('hello world');
});

app.get('/table', function (req, res) {
  res.header("Access-Control-Allow-Origin", "*");
  // return;
  res.json({
      code: 0,
      msg: "ok",
      count:20,
      data: [
        {id: 0,name: "dde6b6",price: "1230",age:0,addr:"dde6b6dde6b6dde6b6dde6b6dde6b6dde6b6dde6b6dde6b6",sign:"ch_dde6b6",experience:"qqdde6b6",score:0},
        {id: 1,name: "cab0a9",price: "1231",age:1,addr:"cab0a9",sign:"ch_cab0a9",experience:"qqcab0a9",score:1,province:"广东省",city:"广州市",county:"详细地址"},
        {id: 2,name: "b6d168",price: "1232",age:2,addr:"b6d168",sign:"ch_b6d168",experience:"qqb6d168",score:2},
        {id: 3,name: "21c05a",price: "1233",age:3,addr:"21c05a",sign:"ch_21c05a",experience:"qq21c05a",score:3},
        {id: 4,name: "46deb5",price: "1234",age:4,addr:"46deb5",sign:"ch_46deb5",experience:"qq46deb5",score:4},
        {id: 5,name: "c4b780",price: "1235",age:5,addr:"c4b780",sign:"ch_c4b780",experience:"qqc4b780",score:5},
        {id: 6,name: "40d3ad",price: "1236",age:6,addr:"40d3ad",sign:"ch_40d3ad",experience:"qq40d3ad",score:6},
        {id: 7,name: "fa0f66",price: "1237",age:7,addr:"fa0f66",sign:"ch_fa0f66",experience:"qqfa0f66",score:7},
        {id: 8,name: "d0a760",price: "1238",age:8,addr:"d0a760",sign:"ch_d0a760",experience:"qqd0a760",score:8},
        {id: 9,name: "f36092",price: "1239",age:9,addr:"f36092",sign:"ch_f36092",experience:"qqf36092",score:9},
        {id: 10,name: "4e2da8",price: "12310",age:10,addr:"4e2da8",sign:"ch_4e2da8",experience:"qq4e2da8",score:10},
        {id: 11,name: "3dc9ec",price: "12311",age:11,addr:"3dc9ec",sign:"ch_3dc9ec",experience:"qq3dc9ec",score:11},
        {id: 12,name: "1df68a",price: "12312",age:12,addr:"1df68a",sign:"ch_1df68a",experience:"qq1df68a",score:12},
        {id: 13,name: "c1bf69",price: "12313",age:13,addr:"c1bf69",sign:"ch_c1bf69",experience:"qqc1bf69",score:13},
        {id: 14,name: "ca8149",price: "12314",age:14,addr:"ca8149",sign:"ch_ca8149",experience:"qqca8149",score:14},
        {id: 15,name: "7c5586",price: "12315",age:15,addr:"7c5586",sign:"ch_7c5586",experience:"qq7c5586",score:15},
        {id: 16,name: "5cf2d",price: "12316",age:16,addr:"5cf2d",sign:"ch_5cf2d",experience:"qq5cf2d",score:16},
        {id: 17,name: "a87338",price: "12317",age:17,addr:"a87338",sign:"ch_a87338",experience:"qqa87338",score:17},
        {id: 18,name: "fc07d",price: "12318",age:18,addr:"fc07d",sign:"ch_fc07d",experience:"qqfc07d",score:18},
        {id: 19,name: "8e55c5",price: "12319",age:19,addr:"8e55c5",sign:"ch_8e55c5",experience:"qq8e55c5",score:19},
      ]
  })
  console.log('ok',req.query)

//   for(var i=0;i<20;i++){
//         var radom = Math.floor(Math.random()*16777215).toString(16)
//       console.log('{id: '+ i +',name: "'+ radom +'",price: "123'+ i +'",age:'+i+',addr:"'+radom+'",sign:"ch_'+radom+'",experience:"qq'+radom+'",score:'+i+'},')
//   }
});






app.listen(3002, function () {
  console.log('访问```：127.0.0.1:3002');
});